//
//  AqiView.m
//  WeatherGuide
//
//  Created by lanou3g on 15/12/22.
//  Copyright © 2015年 李明. All rights reserved.
//

#import "AqiView.h"

#import "Aqi.h"

@interface AqiView ()


@end


@implementation AqiView

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self allViews];
    }
    return self;
}

- (void)allViews
{
    
    CGSize size = [UIScreen mainScreen].bounds.size;
    self.healthLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 300, size.width / 4 - 20, 50)];
    self.healthLabel.text = @"健康影响:";
    self.healthLabel.textColor = [UIColor whiteColor];
    [self addSubview:self.healthLabel];
    
    self.impactLabel = [[UILabel alloc] initWithFrame:CGRectMake(size.width / 4, 300, size.width / 4 * 3 - 20, 100)];
    self.impactLabel.text = @"暂无";
    self.impactLabel.numberOfLines = 0;
    self.impactLabel.textColor = [UIColor whiteColor];
    self.impactLabel.font = [UIFont systemFontOfSize:15];
    [self addSubview:self.impactLabel];
    
    self.measuresLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 400,size.width / 4 - 20, 50)];
    self.measuresLabel.text = @"建议措施:";
    self.measuresLabel.numberOfLines = 0;
    self.measuresLabel.textColor = [UIColor whiteColor];
    [self addSubview:self.measuresLabel];
    
    self.adviceLabel = [[UILabel alloc] initWithFrame:CGRectMake(size.width / 4, 400, size.width / 4 * 3 - 20, 100)];
    self.adviceLabel.text = @"暂无";
    self.adviceLabel.numberOfLines = 0;
    self.adviceLabel.textColor = [UIColor whiteColor];
    self.adviceLabel.font = [UIFont systemFontOfSize:15];
    [self addSubview:self.adviceLabel];
}

- (void)setAqi:(Aqi *)aqi
{
//    NSLog(@"%@",aqi.qlty);
    if ([aqi.qlty isEqualToString:@"优"]) {
        self.impactLabel.text = @"空气非常好,适合各类户外活动,走出去多呼吸一下新鲜空气吧。";
        self.adviceLabel.text = @"各类人群可多参加户外活动,多呼吸一下清新的空气。";
    }else if ([aqi.qlty isEqualToString:@"良"]){
        self.impactLabel.text = @"空气质量还不错哦,可户外活动.特别敏感人群需要注意下。";
        self.adviceLabel.text = @"除少数对某些污染特别容易过敏的人群外,其他人群可以正常进行室外活动。";
    }else if ([aqi.qlty isEqualToString:@"轻度污染"]){
        self.impactLabel.text = @"空气质量轻度污染,放好心态,健康生活!儿童、老年人及心脏病、呼吸疾病者应尽量减少大量户外运动。";
        self.adviceLabel.text = @"老人、儿童、呼吸系统等疾病患者减少长时间、高强度的户外活动。";
    }else if ([aqi.qlty isEqualToString:@"中度污染"]){
        self.impactLabel.text = @"空气质量中度污染,空气较差,适量减少户外运动，减少污染，为蓝天做点贡献!儿童、老年人及心脏病、呼吸疾病者应尽量避免外出。";
        self.adviceLabel.text = @"儿童、老人、呼吸系统等疾病患者应尽量减少外出,停留在室内,一般人群应适量减少户外活动。";
    }else if ([aqi.qlty isEqualToString:@"重度污染"]){
        self.impactLabel.text = @"空气污染如此严重，让人无法忍受,减少户外运动!儿童、老年人及心脏病、呼吸疾病者应停留在室内。";
        self.adviceLabel.text = @"儿童、老人、呼吸系统等疾病患者应停留在室内,停止户外运动,一般人群减少户外活动。";
    }else if ([aqi.qlty isEqualToString:@"严重污染"]){
        self.impactLabel.text = @"空气严重污染，空气状况极差,对健康有严重危害，简直让人无法呼吸,避免户外运动!儿童、老年人及心脏病、呼吸疾病者应停留在室内。";
        self.adviceLabel.text = @"儿童、老人、呼吸系统等疾病患者应停留在室内,避免体力消耗,除有特殊需要的人群外，一般人群尽量不要停留咋室外。";
    }else{
//        self.impactLabel.text = @"暂无";
//        self.adviceLabel.text = @"暂无";
    
    }
    
    
    CGFloat heigt =  [AqiView heightFormString:self.impactLabel.text];
    CGRect rect = self.impactLabel.frame;
    rect.size.height = heigt;
    self.impactLabel.frame = rect;
    
    heigt = [AqiView heightFormString:self.healthLabel.text];
    rect = self.healthLabel.frame;
    rect.origin.y = self.impactLabel.frame.origin.y;
    rect.size.height = heigt;
    self.healthLabel.frame = rect;
    
    heigt = [AqiView heightFormString:self.adviceLabel.text];
    rect = self.adviceLabel.frame;
    rect.size.height = heigt;
    rect.origin.y = self.impactLabel.frame.origin.y + self.impactLabel.frame.size.height + 10;
    self.adviceLabel.frame = rect;
    
   CGRect hrect = self.healthLabel.frame;
    self.measuresLabel.frame = CGRectMake(hrect.origin.x, rect.origin.y, hrect.size.width, hrect.size.height);

}




+ (CGFloat)heightFormString:(NSString *)string
{
    
    CGSize size = CGSizeMake([UIScreen mainScreen].bounds.size.width / 4 * 3 - 20, 1000);
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    CGRect rect = [string boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic
                                     context:nil];
    return rect.size.height;
}

@end
